﻿using System;
using System.Text;

class GenomeDecoder
{
    static void Main()
    {
        //10A15G3CA6T19C
        string nAndM = Console.ReadLine();
        string[] splitedNAndM = nAndM.Split(' ');
        int n = int.Parse(splitedNAndM[0]);
        int m = int.Parse(splitedNAndM[1]);

        string encodedGenome = Console.ReadLine();
        StringBuilder decodedGenome = new StringBuilder();
        StringBuilder baseCount = new StringBuilder();

        for (int i = 0; i < encodedGenome.Length; i++)
        {
            if (Char.IsDigit(encodedGenome, i))
            {
                baseCount.Append(encodedGenome[i]);
            }
            else
            {
                int baseNumber = 1;
                if (int.TryParse(baseCount.ToString(), out baseNumber) && baseNumber > 1)
                {
                    decodedGenome.Append(new String(encodedGenome[i], baseNumber));
                }
                else
                {
                    decodedGenome.Append(encodedGenome[i]);
                }
                baseCount.Clear();
            }
        }
        int lineCount = 1;
        int multiplyer = 0;
        for (int i = n; i <= decodedGenome.Length; i += n)
        {
            for (int j = multiplyer; j < multiplyer + n; j++)
            {
                Console.Write("{0}", lineCount);
                Console.Write(decodedGenome[j].ToString());
                if (j % m == 0)
                {
                    Console.Write(" ");
                }
            }
            lineCount++;
            multiplyer += n;
            Console.WriteLine();
        }
        Console.WriteLine(decodedGenome.ToString());
    }
}